<?php


namespace App\Http\Searchs\Order;


use Illuminate\Database\Query\Builder;
use LTools\Searchs\SearchAbstract;

class IndexSearch extends SearchAbstract
{

    /**
     * 关系映射.
     *
     * @return array
     */
    protected function relationship(): array
    {
        return [
            'intercept_status' => '=',
            'status' => '=',
            'customs_status' => 'closure',
            'number' => '=',
            'code' => '=',
            'customer_id' => '=',
        ];
    }

    /**
     * @param $value
     * @return \Closure
     * @author luffyzhao@vip.126.com
     */
    protected function getCustomsStatusAttribute($value)
    {
        return function (Builder $builder) use ($value) {
            if (!empty($value)) {
                $builder->whereIn('id', function (Builder $builder) use ($value) {
                    $builder->from('order_customs')->select(['order_id']);
                    $builder->where('status', '=', $value);
                });
            };
        };
    }
}